0, In this demonstration, we are going to look at calling a DLL function that returns a string.
9, Here we have a simple application that returns to us the location of the Windows directory by calling one of the Windows API.
18, To run this application, click the Get Windows Directory button.
22, Notice that we get a message box that tells us the location that Microsoft Windows is currently installed in.
31, Let's go ahead and run this application one more time, and this time we'll begin with the F8 button.
37, This will allow us to step through our code to see what is actually happening.
42, We click the Get Windows Directory button and the first line of code is the string function which sets our string variable WinDir to a character string of length 255 null values.
61, The reason we do this is that we need to pass a string to the DLL that's large enough to hold any potential return value.
69, The next statement is where we're actually calling into our DLL, and we're calling the GetWindowsDirectory API function.
77, Here you'll see that we have a ReturnSize return value.
81, What this actually is going to contain is the length of the string that comes back from the DLL.
88, As we make the actual call to the DLL, the WinDir variable that's being passed to the DLL is actually going to be modified and this variable will contain the new string or the location of the Windows directory.
104, As we step through again the thing that we do after this is that we need to strip out the remaining null characters that our string contains.
114, Here we'll use the Left function to do that.
119, Finally, we display a message box with our new Windows directory location.
129, So, what we've seen in this application is that when we call into a DLL that returns a string, what we're actually doing is passing a complete string that is an argument to a DLL.
142, The DLL in turn modifies that string and returns it back to our procedure.